package com.guangfeng.yql.comm.bean;

import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class R<T> {
    private Integer code;
    private String message;
    private T data;
    private Integer total;


    public static <T> R<T> comm(Integer code, String message, T data, Integer total) {
        return R.<T>builder().message(message).code(code).data(data).total(total).build();
    }

    public static <T> R<T> comm(Integer code, String message, T data) {
        return comm(code, message, data, null);
    }

    public static <T> R<T> success(T data) {
        return success("操作成功", data);
    }

    public static <T> R<T> success(String message, T data) {
        return comm(Code.SUCCESS, message, data);
    }

    public static <T> R<T> serve_error(String message, T data) {
        return comm(Code.SERVE_ERROR, message, data);
    }

    public static <T> R<T> serve_error(String message) {
        return serve_error(message, null);
    }

    public static <T> R<T> parameter_error(String message) {
        return comm(Code.PARAMETER_ERROR, message, null);
    }
}
